package com.zr.planClass.controller;

import com.zr.planClass.model.legalandperson.*;
import com.zr.planClass.service.LegalPersonAndLegalPlanService;
import com.zr.util.ResultBuilderVo;
import com.zr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by 非常狂躁的猪 on 2019/12/24.
 */
@RestController
@CrossOrigin
public class LegalPersonAndLegalPlanController {

    @Autowired
    private LegalPersonAndLegalPlanService legalPersonAndLegalPlanService;

    @PostMapping("legalPlant/query")   //分页查询
    public ResultVo queryAllPersonAndPlan(@RequestBody PersonAndPlanSelectVo personAndPlanSelectVo){

        ResultVo resultVo = legalPersonAndLegalPlanService.queryAllPersonAndPlan(personAndPlanSelectVo);

        return resultVo;
    }

    @GetMapping("legalPerson/ofCurrentUser")  //法人下拉框查询
    public ResultVo queryLegalPerson(String _){
        User user1 = new User();
        user1.setUserId(1);
        ResultVo resultVo = legalPersonAndLegalPlanService.queryLegalPerson(user1);
        return  resultVo;
    }

    @PostMapping("legalPlant/add")  //新增
    public ResultVo addPlan(@RequestBody @Valid  LegalPlanAddVo legalPlanAddVo, BindingResult bindingResult){

        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        ResultVo resultVo = legalPersonAndLegalPlanService.addLegalPlant(legalPlanAddVo);
        return resultVo;
    }

    @PostMapping("legalPlant/updatestatus") //修改状态
    public ResultVo updatestatus(@RequestBody LegalPlantUpdateStatusVo legalPlantUpdateStatusVo){
        ResultVo resultVo = legalPersonAndLegalPlanService.updatestatus(legalPlantUpdateStatusVo);
        return resultVo;
    }

    @PostMapping("legalPlant/update")  //修改
    public ResultVo update(@RequestBody @Valid LegalPlanUpdateVo legalPlanUpdateVo,BindingResult bindingResult){
       // System.out.println(legalPlanUpdateVo.getId());  //id为null
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        ResultVo resultVo = legalPersonAndLegalPlanService.update(legalPlanUpdateVo);
        return resultVo;
    }


}








































